Skip to content

Hide empty Text view for documents with no text content#613

Open
hoyla wants to merge 3 commits intomainfrom
ljh-previewswitcher-no-text-if-no-text
Open

Hide empty Text view for documents with no text content#613
hoyla wants to merge 3 commits intomainfrom
ljh-previewswitcher-no-text-if-no-text

Conversation

@hoyla
Copy link
Contributor

@hoyla hoyla commented Mar 14, 2026

Fixes #325

When a document has OCR text but no extracted text content (e.g. an OCR'd image), the Text tab was still shown in the viewer and could be selected or defaulted to, displaying a blank page.

But it was even worse if you opened an image that had no OCRable text. Here the view mode choices were Text (which showed nothing) and Preview (which showed the image), with the default being Text. So by default for non-textual images, users got a blank page and the impression that they had opened a broken or empty file.

This change removes empty Text view modes from the available views. There's a sensible cascade through the default views on opening a doc, even when the user is pushed to a particular view mode (e.g. with ?view=text in the URL). If there's no text, show OCR; if there's no OCR, show preview.

Before, when someone opens an image document that doesn't have any OCR text:

Picture 272

After, opening the same document:

Picture 273

Note that there is no Text view available at the bottom.

Changes:

  • Add hasTextContent() helper to check for non-empty text contents
  • Update PreviewSwitcher to hide the Text tab when text is empty
  • Update PreviewSwitcher validation and fallback to skip empty text
  • Update getDefaultView() to prefer preview over empty text view
  • Add previewStatus to the frontend Resource type (already sent by backend, used by JS components, but missing from the TS type)
  • Add tests for getDefaultView() and hasTextContent()

How has this change been tested?

  • Local dev environment - tried opening a lot of different document types but can't claim to have tried every route and combination

When a document has OCR text but no extracted text content (e.g. an
OCR'd image), the Text tab was still shown in the viewer and could be
selected or defaulted to, displaying a blank page.

Changes:
- Add hasTextContent() helper to check for non-empty text contents
- Update PreviewSwitcher to hide the Text tab when text is empty
- Update PreviewSwitcher validation and fallback to skip empty text
- Update getDefaultView() to prefer preview over empty text view
- Add previewStatus to the frontend Resource type (already sent by
  backend, used by JS components, but missing from the TS type)
- Add tests for getDefaultView() and hasTextContent()
@hoyla hoyla added document viewer ux/ui fix Departmental tracking: fix labels Mar 14, 2026
hoyla added 2 commits March 14, 2026 10:42
- Remove unnecessary undefined guard from hasTextContent (text is
  non-optional on Resource)
- Use hasTextContent() in getDefaultView instead of repeating the
  inline trim/length check
- Use idiomatic trim() !== '' comparisons instead of trim().length > 0
Give makeResource a default empty text so callers only need to pass
overrides for the fields relevant to each test case.
@hoyla hoyla linked an issue Mar 14, 2026 that may be closed by this pull request
@hoyla hoyla marked this pull request as ready for review March 14, 2026 10:59
@hoyla hoyla requested a review from a team as a code owner March 14, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

document viewer fix Departmental tracking: fix ux/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refine default view mode for images in Giant document viewer

1 participant